#include "..\headers\ListOf.h"

int main() {
  int cnt = 0, stacktop = 0;  // count the number start 0
  int m, flag = 1;
  scanf("%d", &m);
  int n, k;
  scanf("%d %d", &n, &k);
  int check[k][n] = {0};
  for (int i = 0; i < k; i++)
    for (int j = 0; j < n; j++) scanf("%d", &check[i][j]);

  for (int i = 0; i < k; i++) {
    int stack[m] = {0};
    cnt = 1, stacktop = 0, flag = 1;
    for (int j = 0; j < n;) {
      if (check[i][j] == cnt && stacktop < m) {
        cnt++;
        j++;
        continue;
      }
      if (stacktop != 0 && stack[stacktop - 1] == check[i][j]) {
        stack[stacktop - 1] = 0;
        stacktop--;
        j++;
        continue;
      }
      if (check[i][j] != cnt && stacktop < m && cnt <= n) {  // push
        stack[stacktop++] = cnt;
        cnt++;
        continue;
      }

      flag = 0;
      break;
    }
    if (flag == 1)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
